<?php

namespace app\index\model;

use think\Model;


class Smallvideo extends Model
{
    // 表名
    protected $name = 'news_smallvideo';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 定义时间戳字段名
    protected $createTime = "create_time";
    protected $updateTime = "update_time";
    protected $deleteTime = false;
    protected $append = [
        'userinfo',
        'comment'
    ];
    public function getUserinfoAttr($value,$data){
    	return db("members")->field("member_id,avatar,nickname")->where("member_id",$data['member_id'])->find();
    }
    public function getCommentAttr($value,$data){
    	$where['news_id']=$data['id'];
    	$where['parent_id']=0;
    	$where['type']=4;
    	$where['comment_id']=0;
    	return db("news_comment")->where($where)->count();
    }
}


